/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import domain.Usuario;
import facade.LoginFacadeLocal;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author jabes
 */
@ManagedBean(name = "LoginController")
@SessionScoped
public class LoginController {

    @EJB
    private LoginFacadeLocal loginService;
    private Usuario usuario = new Usuario();
    private boolean logado = false;

    public String login() {
        logado = loginService.verificarUsuario(usuario);
        return logado ? "index" : "falha";
    }

    public String logout() {
        if (logado) {
            HttpSession session = (HttpSession) FacesContext.getCurrentInstance().
                    getExternalContext().getSession(true);
            session.invalidate();
            usuario = null;
            logado = false;
        }
        return "logout";
    }

    //metodos getter
    public boolean isLogado() {
        return logado;
    }

    public Usuario getUsuario() {
        return usuario;
    }
}
